<?php
/*
Template Name: Cart Page
*/

get_header();
$active_option = get_option('azio_style_option', 'option_not_set');
if (have_posts()): the_post();
    $permalink = get_permalink();
    $title = get_the_title();
    ?>

    <div id="main-container" class="<?php echo $active_option->main_container; ?>">
        <div class="page-top-leader omega<?php echo ' '.$active_option->page_top_leader; ?>">
            <div class="container_12 relatived clearfix">
                <h1 class="page-title"><?php echo $title; ?></h1>
                <?php
                if (function_exists('yoast_breadcrumb')) {
                    yoast_breadcrumb('<div class="breadcrumb">', '</div>');
                }
                ?>
            </div>
        </div>
        <!-- .page-top-leader -->
        <div class="container_12 full-container">
            <div class="cart-info grid_9">
                <table>
                    <thead>
                    <tr>
                        <td class="image">Hình ảnh</td>
                        <td class="name">Tên sản phẩm</td>
                        <td class="quantity">Số lượng</td>
                        <td class="price">Đơn giá (VNĐ)</td>
                        <td class="total">Tổng cộng</td>
                    </tr>
                    </thead>
                    <tbody>
                    <?php if (isset($_SESSION['cart']) && !empty($_SESSION['cart'])) {
                        foreach ($_SESSION['cart'] as $cart_product) {
                            ?>
                            <tr id="cart-product-<?php echo $cart_product['id']; ?>">
                                <td class="image">
                                    <a href="<?php echo $cart_product['link']; ?>" title="<?php echo esc_attr($cart_product['name']); ?>">
                                        <img src="<?php echo $cart_product['image']; ?>" alt="<?php echo esc_attr($cart_product['name']); ?>" width="100" height="100"/>
                                    </a>
                                </td>
                                <td class="name"><?php echo $cart_product['name']; ?></td>
                                <td class="quantity">
                                    <div class="plus-min"><span class="icomoon plus_qty" data-icon="&#xe01a;"></span>
                                        <span class="icomoon minus_qty" data-icon="&#xe01b;"></span></div>
                                    <input type="text" value="<?php echo $cart_product['num']; ?>" size="1">

                                    <a href="javascript:void(0);" onClick="updateCart(this, <?php echo $cart_product['id']; ?>);" title="Cập nhật">
                                        <span data-icon="&#xe00b;" class="update_cart icomoon"></span>
                                    </a>

                                    <a href="javascript:void(0);" onClick="deleteItem(this, <?php echo $cart_product['id']; ?>);" title="Xóa sản phẩm">
                                        <span data-icon="&#xe004;" class="remove_cart icomoon"></span>
                                    </a>
                                </td>
                                <td class="price"><?php echo number_format($cart_product['price'], 0, ',', ','); ?> ₫</td>
                                <td class="total"><?php echo number_format(($cart_product['price'] * $cart_product['num']), 0, ',', ','); ?> ₫</td>
                            </tr>
                        <?php
                        } // endforeach
                    } // endif
                    ?>
                    </tbody>
                </table>
            </div>
            <!-- end .cart-info -->
            <?php
            if (isset($_SESSION['cart']) && !empty($_SESSION['cart'])) {
                $cart_sum = cal_total_price($_SESSION['cart']);
            } else {
                $cart_sum['total'] = 0;
            } ?>
            <div class="right grid_3 omega">
                <div class="cart-total">
                    <table id="total">
                        <tbody>
                        <tr>
                            <td><strong>Tổng:</strong></td>
                            <td class="total"><?php echo number_format($cart_sum['total'], 0, ',', ','); ?> ₫</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="cart-buttons">
                    <a class="checkout-btn" href="<?php echo WP_HOME ?>/dat-hang/">
                        <i aria-hidden="true" data-icon="&#xe019;" class="icomoon"></i> <span>Đặt hàng</span> </a>
                    <a class="shopping-btn" href="<?php echo WP_HOME ?>/hai-san/">
                        <i aria-hidden="true" data-icon="&#x25e0;" class="icomoon"></i> <span>Tiếp tục mua hàng</span>
                    </a>
                    <a class="shopping-btn" href="javascript:void(0);" onClick="javascript:deleteCart(this);" style="background: #8d2e1e;">
                        <i aria-hidden="true" data-icon="&#xe004;" class="icomoon"></i> <span>Xóa giỏ hàng</span>
                    </a>
                </div>
                <!-- end .cart-buttons -->
            </div>
            <!-- end .coupon-wraper --> </div>
        <!-- end .container_12 -->

        <?php get_template_part('block', 'baseinfo') ?>
        <!-- end .base-info -->
    </div>
    <!-- end #main-container -->


<?php endif ?>

<?php get_footer() ?>